package com.xieyunjie.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

/**
 * @program: 0812springboot
 * @author: 雷哥
 * @create: 2019-12-16 11:35
 **/
@Aspect
@Component
@EnableAspectJAutoProxy  //这个可以不加
public class CacheAspect {
    //声明切面
    public static final String POINTCUT1="execution(* com.xieyunjie.service.impl.UserServiceImpl.getOne(..))";

    @Around(POINTCUT1)
    public  Object cache(ProceedingJoinPoint pjp) throws Throwable {

        Object[] args = pjp.getArgs();
        String id = (String) args[0];
        System.out.println(id);
        //使用id从缓存里面查询数据
        Object cacheObj = null;
        if (cacheObj == null) {
            Object proceed = pjp.proceed();//执行目标方法
            //放入缓存
            //返回
            return proceed;
        } else {
            return cacheObj;
        }
    }


}
